﻿using System;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace SmartCity.Shared
{
    /// <summary>
    /// Json结果扩展类
    /// </summary>
    public class JsonResultFactory
    {
        /// <summary>
        /// 未授权结果
        /// </summary>
        /// <param name="value"></param>
        public static JsonResult UnauthorizedResult()
        {
            return new JsonResult(UnauthorizedResponse.Unauthorized())
            {
                StatusCode = StatusCodes.Status401Unauthorized
            };
        }

        /// <summary>
        /// 未找到资源结果
        /// </summary>
        public static JsonResult NotFound()
        {
            return new JsonResult(NotFoundResponse.NotFound())
            {
                StatusCode = StatusCodes.Status404NotFound
            };
        }

        /// <summary>
        /// 禁止访问结果
        /// </summary>
        public static JsonResult Forbidden()
        {
            return new JsonResult(ForbiddenResponse.Forbidden())
            {
                StatusCode = StatusCodes.Status403Forbidden
            };
        }

        /// <summary>
        /// 系统异常结果
        /// </summary>
        public static JsonResult Error(string msg)
        {
            return new JsonResult(ErrorResponse.Error(msg))
            {
                StatusCode = StatusCodes.Status500InternalServerError
            };
        }

        /// <summary>
        /// 系统异常结果
        /// </summary>
        public static JsonResult Error(Exception ex)
        {
            return new JsonResult(ErrorResponse.Error(ex))
            {
                StatusCode = StatusCodes.Status500InternalServerError
            };
        }
    }
}